<!doctype html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <title>添加系列</title>
	    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/lang/zh-cn/Convert_Pinyin.js"></script>
    </head>
    <body>
       <div class="easyui-container-fluid">
          <div class="easyui-panel" style="border: none;">
            <div class="nav" id="nav"></div> 
            <div class="easyui-panel" style="border:none;">
              <form id="ff" method="post">
                <div style="margin-bottom:20px">
                    <label class="item-label"><span class="item-required">*</span>品类：</label>
                    <select class="easyui-combobox" id="categorySelect" name="categoryCode" style="width:128px;" required="required" >
                    </select>
                    <label class="item-label"><span class="item-required">*</span>品牌：</label>
                    <select class="easyui-combobox" id="brandSelect" name="brandCode" style="width:128px;" validType="notNull['#brandSelect']" required="required" ></select>
                  <label class="item-label"><span class="item-required">*</span>名称：</label>
                  <input class="easyui-textbox name" type="text" name="name" id="name" data-options="required:true">
                </div>
                <div style="margin-left:100px;margin-botttom:20px;">
                    <a href="javascript:void(0)" class="easyui-linkbutton c8" onclick="submitForm()" style="width:80px">保存</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="cancel()" style="width:80px">取消</a>
                </div>              
              </form>     
            </div>
          </div> 
       </div>  
    </body>
    <script type="text/javascript">
         var id = getQueryParameter("id"),categoryCode=getQueryParameter("categoryCode");
         $(function(){
             setNav();
             $.when(initBrandSelect("brandSelect"), initCategorySelect("categorySelect")).done(function(){initFormData()});
         });

         function initFormData(){
             if(id){
                 $.ajax({
                     url:config.url +"/series/getById/"+id,
                     type:'get',
                     xhrFields:{withCredentials:true},
                     success:function(data){
                         //填充表单
                         if(data.code == 200){
                             var formdata = changeProperty2String(data.msg);
                             $("#ff").form("load",formdata);
                             //model brand readonly
                             $("#brandSelect").combobox("readonly",true);
                             $("#categorySelect").combobox("readonly",true);
                         }
                     },
                     error:function(){

                     }
                 });
             }else {
                $("#categorySelect").combobox("select",categoryCode);
             }
         }

         function submitForm() {
             $("#ff").form("submit", {
                 onSubmit: function () {
                     var formData = getFormData(document.getElementById("ff"));
                     var url = "/insert";

                     if(id){
                         url = "/update"
                         formData.id = id;
                     }
                     $.ajax({
                         url:config.url+"/series"+url,
                         type:"post",
                         data:JSON.stringify(formData),
                         dataType:'json',
                         contentType:'application/json;charset=UTF-8',
                         xhrFields:{withCredentials:true},
                         beforeSend:function(){
                             $.messager.progress({
                                 title:"请稍等",
                                 interval:50,
                                 text:"操作进行中..."
                             });
                         },
                         complete:function(){
                             $.messager.progress("close");
                         },
                         success:function(data){
                             if(data.code==200){
                                 $.messager.alert("提示",data.msg,"info",function(){
                                     window.parent.closeCurrentTab(true);
                                 });
                             }else{
                                 $.messager.alert("提示",data.msg,"error");
                             }
                         },
                         error:function(XMLHttpRequest,textStatus,thrown){
                             $.messager.alert("提示","操作失败","error");
                         }
                     });


                 }
             });
         }

         function cancel(){
             window.parent.closeCurrentTab();
         }
    </script>
</html>
